<template>
  <div>
    <def-layout type="col0-24" :page="page" @invoke="invoke">
      <div slot="search" class="form-items">
        <el-form-item>
          <el-input v-model="formSearch.keyword" placeholder="名称" />
        </el-form-item>
        <el-form-item>
          <el-select v-model="formSearch.used" placeholder="请选择">
            <el-option
              v-for="item in constants.used.values()"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
      </div>
      <div slot="content" class="grid">
        <page-grid v-if="self!=null" :parent="self">
          <div slot="columns">
            <el-table-column prop="used" align="center" label="状态" width="90">
              <template slot-scope="scope">
                <column-filter v-model="scope.row.used" type="used" @click="filter" />
              </template>
            </el-table-column>
            <el-table-column prop="id" align="center" label="编码" width="100" />
            <el-table-column prop="name" align="left" label="名称" width="300" />
            <el-table-column prop="orderCount" sortable align="right" label="供货次数" width="150" />
            <el-table-column prop="orderSales" sortable align="right" label="供货金额" width="150" />
            <el-table-column prop="orderPayment" sortable align="right" label="已付金额" width="150" />
            <el-table-column prop="orderWeight" sortable align="right" label="供货重量(吨)" width="150" />
          </div>
        </page-grid>
      </div>
    </def-layout>
    <editFrom ref="editDrawer" :page="page" :params="modalParams" />

  </div>
</template>
<script>
import adminSupport from 'lola-admin-support-el'
import editFrom from '@/views/base-group/store-manage/edit.vue'

export default {
  name: 'StoreManage',
  components: {
    editFrom
  },
  mixins: [adminSupport.mixins.index],
  data() {
    return {
      name: 'StoreManage',
      formSearch: { keyword: '', used: '' },
      self: null,
      mode: 'modal'
    }
  },
  created() {
    this.init()// 页面自定义初始化
  },
  methods: {
    init() {
      var that = this
      that.loadData()// 加载数据(按钮+列表) 扩展需重写该方法
      this.self = that
    },
    search() {
      const queryList = []
      if (!String.isNullOrEmpty(this.formSearch.keyword)) {
        queryList.push({ 'key': 'name', 'value': this.formSearch.keyword, 'oper': ':', 'join': 'and' })
      }
      if (!String.isNullOrEmpty(this.formSearch.used) && this.formSearch.used !== 'All') queryList.push({ 'key': 'used', 'value': this.formSearch.used, 'oper': '=', 'join': 'and' })

      this.dataGrid.params.queryList = queryList
      this.refresh()
    },
    bindSearch() {
      this.formSearch = { keyword: '', used: '' }
    },
    buildOtherBtn(item, btn) {
      if (item.code === 'm7117') {
        btn.opt = 'initStore'
        btn.type = 'danger'
      }
      if (item.code === 'm7118') {
        btn.opt = 'syncOrder'
        btn.type = 'primary'
      }
    },
    initStore(row) {
      const that = this
      const loading = that.$loading()
      const url = that.page.router.remoteUrl + '/init/' + row.id
      that.service.get(url, {}).then(res => {
        loading.close()
        if (res.code !== 200) {
          that.$message.error(res.message)
          return
        }
        that.$message.success('初始化请求发送成功!')
      }).catch((e) => {
        loading.close()
      })
    },
    syncOrder(row) {
      const that = this
      const loading = that.$loading()
      const url = that.page.router.remoteUrl + '/syncOrder/' + row.id
      that.service.get(url, {}).then(res => {
        loading.close()
        if (res.code !== 200) {
          that.$message.error(res.message)
          return
        }
        that.$message.success('同步请求发送成功!')
      }).catch((e) => {
        loading.close()
      })
    }
  }
}
</script>
